package chapter2.No2_2_synchronized同步语句块.eSynchronized代码块之间的同步性;

/**
 * !
 *
 * @author liujian
 * @version 2016/11/11 0011
 */
public class ServiceClass {
    public void methodA(){
        System.out.println("进入methodA");
        synchronized (this){
            try {
                System.out.println("线程"+Thread.currentThread().getName()+" methodA方法开始");
                Thread.sleep(1000);
                System.out.println("线程"+Thread.currentThread().getName()+" methodA方法结束");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("退出methodA");

    }

    public void methodB() {
        System.out.println("进入methodB");
        synchronized (this) {
            try {
                System.out.println("线程"+Thread.currentThread().getName()+" methodB方法开始");
                Thread.sleep(1000);
                System.out.println("线程"+Thread.currentThread().getName()+" methodB方法结束");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("退出methodB");
    }
}
